<template>
  <div class="mall-container">
    <!-- 顶部标题和搜索框 -->
    <div class="header">
      <h1 class="title">机器人之家</h1>
      <div class="search">
        <input type="text" placeholder="搜索商品" v-model="searchText">
        <i class="search-icon"></i>
      </div>
    </div>

    <!-- 滑动菜单 -->
    <div class="scroll-menu">
      <div class="menu-wrapper" ref="menuWrapper">
        <div class="menu-item" v-for="(item, index) in menuList" :key="index" @click="navigateTo(item.path)">
          <i :class="item.icon"></i>
          <span>{{ item.name }}</span>
        </div>
      </div>
    </div>

    <!-- 功能区块 -->
    <div class="function-grid">
      <div class="grid-item" v-for="(item, index) in functionList" :key="index" @click="navigateTo(item.path)" >
        <i :class="item.icon"></i>
        <img :src="item.img" alt="function"/>
        <span>{{ item.name }}</span>
      </div>
    </div>

    <!-- 广告轮播图 -->
    <div class="swiper-container">
      <swiper
          :slides-per-view="1"
          :loop="true"
          :autoplay="{
          delay: 300,
          disableOnInteraction: false
        }"
          :pagination="{ clickable: true }"
      >
        <swiper-slide v-for="(banner, index) in bannerList" :key="index">
          <img :src="banner.imageUrl" :alt="banner.title">
        </swiper-slide>
      </swiper>
    </div>

    <!-- 资讯列表 -->
    <div class="news-section">
      <h2 class="section-title">热门资讯</h2>
      <div class="news-list">
        <div class="news-item" v-for="(news, index) in newsList" :key="index" @click="navigateToForumPost(news.id)">
          <div class="news-content">
            <h3 class="news-title">{{ news.title }}</h3>
            <p class="news-desc">{{ news.description }}</p>
            <div class="news-meta">
              <span class="news-author">{{ news.author }}</span>
              <span class="news-time">{{ news.time }}</span>
              <span class="news-views">{{ news.views }}阅读</span>
            </div>
          </div>
          <div class="news-image">
            <img :src="news.imageUrl" :alt="news.title">
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { Swiper, SwiperSlide } from 'swiper/vue'
import 'swiper/css'
import 'swiper/css/pagination'

const router = useRouter()

// 搜索框数据
const searchText = ref('')

// 滑动菜单数据
const menuList = ref([
  // { name: '推荐', icon: 'recommend-icon', },
  { name: '选品', icon: 'phone-icon', path: "/robot" },
  { name: '比价', icon: 'computer-icon', path: "/compare" },
  { name: '交易', icon: 'clothes-icon', path: "/robot" },
  { name: '使用', icon: 'food-icon', path: "/forum" },
  { name: '社交', icon: 'beauty-icon', path: "/forum" },
  { name: '资讯', icon: 'home-icon', path: "/forum" },
  { name: '培训', icon: 'sports-icon', path: "/forum" },
  { name: '反馈', icon: 'sports-icon', path: "/feedback" },
])

// 功能区块数据
const functionList = ref([
  { name: '工业用', icon: 'seckill-icon',img: "/src/assets/img/phone/robot.svg",path:"/robot" },
  { name: '个人用', icon: 'coupon-icon',img: "/src/assets/img/phone/robot-g.svg",path:"/robot"  },
  { name: '公共服务', icon: 'market-icon',img: "/src/assets/img/phone/robot-copy.svg",path:"/robot"  },
  { name: '特种作业', icon: 'group-icon',img: "/src/assets/img/phone/robot-t.svg",path:"/robot"  },
  { name: '产业链', icon: 'live-icon',img: "/src/assets/img/phone/Robotics.svg",path:"/robot"  },
  { name: '智选', icon: 'points-icon',img: "/src/assets/img/phone/vs.svg",path:"/compare"  },
  { name: '测评', icon: 'checkin-icon',img: "/src/assets/img/phone/rate.svg",path:"/rate"  },
  { name: '会员', icon: 'vip-icon',img: "/src/assets/img/phone/hui.svg",path:"/profile"  }
])

// 跳转方法
const navigateTo = (path) => {
  if (path) {
    router.push(path);
  }
}

// 轮播图数据
const bannerList = ref([
  { imageUrl: "/src/assets/img/phone/a.jpg", title: '活动banner1' },
  { imageUrl: "/src/assets/img/phone/b.jpg", title: '活动banner2' },
  { imageUrl: "/src/assets/img/phone/c.jpg", title: '活动banner3' }
])

// 资讯列表数据
const newsList = ref([
  {
    id: 1,
    title: '最新机器人技术突破：AI自主学习能力大幅提升',
    description: '来自麻省理工的最新研究显示，新一代机器人在自主学习方面取得重大突破...',
    author: '科技前沿',
    time: '2小时前',
    views: '2.3k',
    imageUrl: "/src/assets/img/phone/d.png"
  },
  {
    id: 2,
    title: '家用服务机器人市场分析：2024年增长趋势',
    description: '随着人口老龄化加剧，家用服务机器人市场预计在2024年将达到...',
    author: '市场观察',
    time: '4小时前',
    views: '1.8k',
    imageUrl: "/src/assets/img/phone/e.png"
  },
  {
    id: 3,
    title: '工业机器人应用案例：提升生产效率的成功实践',
    description: '某知名制造企业引入新一代工业机器人后，生产效率提升40%...',
    author: '产业资讯',
    time: '6小时前',
    views: '3.1k',
    imageUrl: "/src/assets/img/phone/f.png"
  },
  {
    id: 4,
    title: '机器人编程教育：培养未来AI人才',
    description: '越来越多的教育机构开始重视机器人编程教育，为未来AI人才储备...',
    author: '教育视角',
    time: '8小时前',
    views: '1.5k',
    imageUrl: "/src/assets/img/phone/d.png"
  }
])

// 页面导航方法
const navigateToForumPost = (postId) => {
  router.push(`/forum/post/${postId}`)
}

</script>

<style scoped>
.mall-container {
  width: 100%;
  height: 100vh;
  background: #f5f5f5;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 10px;
  background: #323333;
  position: sticky;
  top: 0;
  z-index: 10;
}

.title {
  font-size: 15px;
  color: #dddddd;
  font-weight: bold;
}

.search {
  position: relative;
  width: 50%;
}

.search input {
  width: 80%;
  padding: 8px 30px 8px 10px;
  border-radius: 15px;
  border: 1px solid #eee;
  background: #f5f5f5;
  font-size: 12px;
}

.scroll-menu {
  padding: 5px 0;
  background: #fff;
  overflow-x: auto;
}

.menu-wrapper {
  display: flex;
  white-space: nowrap;
}

.menu-item {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  margin: 0 15px;
}
.menu-item span {
  font-size: 13px;
}

.menu-item i {
  font-size: 15px;
  margin-bottom: 3px;
}

.function-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  padding: 5px;
  background: #fff;
}

.grid-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 5px;
}

.grid-item i {
  font-size: 28px;
  margin-bottom: 3px;
}

.grid-item img {
  font-size: 28px;
  margin-bottom: 3px;
}

.grid-item span {
  font-size: 10px;
}

/* 资讯列表样式 */
.news-section {
  background: #fff;
  padding: 15px;
  margin-top: 10px;
}

.section-title {
  font-size: 16px;
  font-weight: bold;
  color: #1e90ff;
  margin-bottom: 15px;
}

.news-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.news-item {
  display: flex;
  padding: 10px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
}

.news-content {
  flex: 1;
  margin-right: 10px;
}

.news-title {
  font-size: 15px;
  font-weight: bold;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.news-desc {
  font-size: 13px;
  color: #666;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.news-meta {
  display: flex;
  gap: 10px;
  font-size: 12px;
  color: #999;
}

.news-image {
  width: 120px;
  height: 90px;
}

.news-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
}

/* 轮播图样式 */
.swiper-container {
  background: #fff;
  padding: 15px;
}

.swiper-container img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: 10px;
}

:deep(.swiper-pagination-bullet) {
  background: #fff;
  opacity: 0.8;
}

:deep(.swiper-pagination-bullet-active) {
  background: #ff6b6b;
}

/* 固定底部导航栏样式 */
.fixed-tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50px;
  background: #fff;
  display: flex;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  z-index: 100;
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 5px 0;
  cursor: pointer;
}

.tab-item i {
  font-size: 20px;
  margin-bottom: 3px;
}

.tab-item span {
  font-size: 12px;
}

.tab-item.active {
  color: #48a1e3;
}

.tab-item.active img {
  color: #48a1e3;
}
</style>



